package com.hbnu.controller;

import com.hbnu.pojo.Request;
import com.hbnu.pojo.Result;
import com.hbnu.service.GoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin(origins = "*")
@Slf4j
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    @GetMapping("/getCategoryList")
    public Result getCategoryList(){
        return Result.success(goodsService.getCategoryList());
    }

    @PostMapping("/getGoodListByCid")
    public Result getGoodListByCid(@RequestBody Request rq){
        return Result.success(goodsService.getGoodListByCid(rq));
    }

    @PostMapping("/getSellingGoodListByCid")
    public Result getSellingGoodListByCid(@RequestBody Request rq){
        return Result.success(goodsService.getSellingGoodListByCid(rq));
    }


    @PostMapping("/getGoodListByContent")
    public Result getGoodListByContent(@RequestBody Request rq){
        return  Result.success(goodsService.getGoodListByContent(rq));
    }

    @PostMapping("/getSellingGoodListByContent")
    public Result getSellingGoodListByContent(@RequestBody Request rq){
        System.out.println(233);
        return Result.success(goodsService.getSellingGoodListByContent(rq));
    }
    @PostMapping("/getGoodListByState")
    public Result getGoodListByState(@RequestBody Request rq){
        return Result.success(goodsService.getGoodListByState(rq));
    }

    @PostMapping("/getGoodListByContentStateCid")
    public Result getGoodListByContentStateCid(@RequestBody Request rq){
        return Result.success(goodsService.getGoodListByContentStateCid(rq));
    }
    @PostMapping("/addCategory")
    public Result addCategory(@RequestBody Request rq){
        try{
            goodsService.addCategory(rq);
            return Result.success();
        }catch (Exception exception){
            return Result.error("重复添加");
        }
    }
    @PostMapping("/addGood")
    public Result addGood(@RequestBody Request rq){
        try{
            goodsService.addGood(rq);
            return Result.success();
        }catch (Exception e){
            return Result.error("重复添加");
        }
    }

    @PostMapping("/modifyGoodGname")
    public Result modifyGoodGname(@RequestBody Request rq){
        goodsService.modifyGoodGname(rq);
        return Result.success();
    }

    @PostMapping("/modifyGoodPrice")
    public Result modifyGoodPrice(@RequestBody Request rq){
        goodsService.modifyGoodPrice(rq);
        return Result.success();
    }

    @PostMapping("/modifyGoodDesc")
    public Result modifyGoodDesc(@RequestBody Request rq){
        goodsService.modifyGoodDesc(rq);
        return Result.success();
    }

    @PostMapping("/modifyGoodSrc")
    public Result modifyGoodSrc(@RequestBody Request rq){
        goodsService.modifyGoodSrc(rq);
        return Result.success();
    }

    @PostMapping("/modifyGoodNum")
    public Result modifyGoodNum(@RequestBody Request rq){
        goodsService.modifyGoodNum(rq);
        return Result.success();
    }

    @PostMapping("/modifyGoodState")
    public Result modifyGoodState(@RequestBody Request rq){
        goodsService.modifyGoodState(rq);
        return Result.success();
    }

    @PostMapping("/updateGoodInfo")
    public Result updateGoodInfo(@RequestBody Request rq){
        goodsService.updateGoodInfo(rq);
        return Result.success();
    }

}
